<template>
  <div>
    <h2>孙子组件</h2>
    <p>msg2:{{ msg2 }}</p>
    <p>$attrs:--- msg2:{{ $attrs.msg3 }}</p>
    <button @click="getParentFun">调用祖级组件方法</button>
    <el-divider></el-divider>
    <p>inject:{{ provide1 }}</p>
    <p>inject:{{ provide2 }}</p>
    <button @click="postChild3">向child3发数据</button>
  </div>
</template>

<script>
export default {
  name: 'child2-page',
  methods: {
    getParentFun() {
      // this.$listeners.parentFun('我是孙子组件数据')
      this.$emit('parentFun', '我是孙子组件数据')
    },
    postChild3() {
      this.$EventBus.$emit('msg', '123')
    }
  },
  inject: ['provide1', 'provide2'],
  props: {
    msg2: {
      type: String,
      default: ''
    }
  },
  inheritAttrs: false,
  created() {
    // 获取父组件中所有绑定属性
    console.log('1111:', this.$attrs) // { msg3: '子组件msg3', type: 'success'}
    // 获取父组件中所有绑定方法
    console.log('2222:', this.$listeners) // {parentFun:f}
  }
}
</script>

<style lang="scss" scoped>
</style>
